package com.example.fuckumusic.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.fuckumusic.R;

public class MyListViewAdapter extends BaseAdapter {

	private Context context;

	private List<Map<String, Object>> data;

	private LayoutInflater inflater;

	public MyListViewAdapter(Context context, List<Map<String, Object>> list) {
		this.data = list;
		this.context = context;
		this.inflater = LayoutInflater.from(context);
	}

	public final class Digest {
		public ImageView imageView;
		public TextView textView, textView2;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Digest digest = null;
		if (convertView == null) {
			digest = new Digest();
			convertView = inflater.inflate(R.layout.listview_item, null);
			digest.imageView = (ImageView) convertView
					.findViewById(R.id.item_img);
			digest.textView = (TextView) convertView
					.findViewById(R.id.item_txt);
			digest.textView2 = (TextView) convertView
					.findViewById(R.id.item_txt2);
			convertView.setTag(digest);
		} else {
			digest = (Digest) convertView.getTag();
		}

		digest.imageView.setBackgroundResource((Integer) data.get(position)
				.get("image"));
		digest.textView.setText((String) data.get(position).get("title"));
		digest.textView2.setText((String) data.get(position).get("content"));
		return convertView;
	}

}
